#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void exectask()
{
	printf("exec a task.\n");
}

void func(int sig)
{
	printf("received signal%d." , sig);
	signal(sig, SIG_DFL);	// return to default handler
}

int main()
{
	
	signal(SIGINT, func);	// ctrl + c
	signal(SIGTERM, func);	// kill pid or killall

	//signal(SIGINT, SIG_IGN);	// ignore signal
	//signal(SIGTERM, SIG_IGN);	// ignore signal

	int ii = 0;
	while(1)
	{
		exectask();
		sleep(5);
	}
}
